<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../../vue.js"></script>
</head>

<body>
  <div id="app">
    <ul>
      <li v-for="c in list">{{c.name}}</li>
    </ul>
    <span>{{total}}</span>
  </div>


  <script>

    var vm = new Vue({
      el: "#app",
      data: {
        list: []
      },
      computed: {
        total() {
          return this.list.reduce((total, item) => {
            return total += item.quantity;
          }, 0)
        }
      },
      mounted() {
        setTimeout(() => {
          fetch('https://api.myjson.com/bins/1h8gwt').then((res) => res.json()).then((result) => {
            this.list = result.products;
          })
        }, 3000)
      }

    })

  </script>
</body>

</html>